# Create your views here.
from django.contrib.sites.models import Site

from django.shortcuts import get_list_or_404
from django.shortcuts import get_object_or_404
from django.shortcuts import render_to_response

from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext

# settings
from django.conf import settings
from chimichanga.banner_viewer.models import Campaign
from chimichanga.banner_viewer.models import Page_Template
from chimichanga.banner_viewer.models import Banner
from chimichanga.banner_viewer.models import Concept

def base(request):
    return render_to_response('404.html',
                             context_instance=RequestContext(request))
    

def campaign_view(request, slug):
    campaign = get_object_or_404(Campaign, slug__exact=slug)
    
    return render_to_response('chimichanga/campaign.html',
                             {'campaign':campaign},
                             context_instance=RequestContext(request))


def concept_view(request, id):

    campaign = get_object_or_404(Campaign, pk=id)
    concepts = campaign.concepts.all().filter(active=True)
    
    for concept in concepts:
        concept.allBanners = concept.banners.all().filter(active=True)
    
    return render_to_response('chimichanga/menu.html',
                          {'campaign':campaign, 'concepts':concepts},
                          context_instance=RequestContext(request))
                          
def banner_view(request, id):

    banner = get_object_or_404(Banner, pk=id)
    page_template = Page_Template.objects.get(banner=banner.id)
    
    return render_to_response('chimichanga/banner.html',
                            {'banner':banner, 'page_template':page_template, },
                            context_instance=RequestContext(request))
                        
def blank_view(request):

    return render_to_response('chimichanga/blank.html',
                            context_instance=RequestContext(request))                        